package com.aishuang.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @Title: MyCorsConfiguration
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/3/8 10:16
 */
@Configuration
public class MyCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedOrigin("*");
        configuration.addAllowedHeader("*");
        configuration.addAllowedMethod("*");
        configuration.setAllowCredentials(true);
        configurationSource.registerCorsConfiguration("/**",configuration);
        CorsWebFilter corsWebFilter = new CorsWebFilter(configurationSource);
        return corsWebFilter;

    }
}
